import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_learn_vi/src/bean/bean_ppt_course.dart';
import 'package:flutter_learn_vi/src/bean/bean_video.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/2/4.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class CourseHttpModel {
  CancelToken _cancelToken;

  ///根据课程 id 来获取视频列表
  Future<List<VideoModel>> getVideoList(
      {@required int videoCourseId, int trainId}) async {
    Map<String, dynamic> map = Map();
    map["videoCourseId"] = videoCourseId;
    if (trainId != null) {
      map["trainId"] = trainId;
    }
    //post请求发送
    ResponseInfo responseInfo = await DioUtils.instance.postRequest(
      url: HttpHelper.videoListUrl,
      jsonMap: map,
      encrypt: true,
      cancelTag: _cancelToken,
    );

    List<VideoModel> _list = [];
    if (responseInfo.success) {
      _list = [];
      List list = responseInfo.data;
      list.forEach((element) {
        VideoModel beanVideoCourse = VideoModel.fromMap(element);
        _list.add(beanVideoCourse);
      });
    } else {
      ToastUtils.showToast("加载视频列表出错:${responseInfo.message}");
    }

    return _list;
  }

  ///根据课程 id 来获取ppt列表
  Future<List<BeanPptCourse>> getPptList({int videolevelId}) async {
    Map<String, dynamic> map = Map();
    map["videolevelId"] = videolevelId;
    //post请求发送
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.videoPptListUrl,
      queryParameters: map,
      cancelTag: _cancelToken,
    );

    List<BeanPptCourse> _list = [];
    if (responseInfo.success) {
      _list = [];
      List list = responseInfo.data;
      list.forEach((element) {
        BeanPptCourse beanVideoCourse = BeanPptCourse.fromMap(element);
        _list.add(beanVideoCourse);
      });
    }

    return _list;
  }
}
